import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";

var _dec, _dec2, _class;

import React, { PureComponent } from 'react';
import { Button, Card, Spin } from 'antd';
import { connect } from 'dva';
import intl from "../../utils/intl";
import formatterCollections from "../../utils/intl/formatterCollections";
import styles from "./style.less?modules";
var TriggerException = (_dec = formatterCollections({
  code: ['cpaas.exceptionComponent']
}), _dec2 = connect(function (state) {
  return {
    isloading: state.error.isloading
  };
}), _dec(_class = _dec2(_class = /*#__PURE__*/function (_PureComponent) {
  _inherits(TriggerException, _PureComponent);

  var _super = _createSuper(TriggerException);

  function TriggerException() {
    var _this;

    _classCallCheck(this, TriggerException);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));
    _this.state = {
      isloading: false
    };

    _this.triggerError = function (code) {
      _this.setState({
        isloading: true
      });

      _this.props.dispatch({
        type: 'error/query',
        payload: {
          code: code
        }
      });
    };

    return _this;
  }

  _createClass(TriggerException, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      return /*#__PURE__*/React.createElement(Card, null, /*#__PURE__*/React.createElement(Spin, {
        spinning: this.state.isloading,
        wrapperClassName: styles.trigger
      }, /*#__PURE__*/React.createElement(Button, {
        type: "danger",
        onClick: function onClick() {
          return _this2.triggerError(401);
        }
      }, intl.get('cpaas.exceptionComponent.view.button.trigger401').d('触发401')), /*#__PURE__*/React.createElement(Button, {
        type: "danger",
        onClick: function onClick() {
          return _this2.triggerError(403);
        }
      }, intl.get('cpaas.exceptionComponent.view.button.trigger403').d('触发403')), /*#__PURE__*/React.createElement(Button, {
        type: "danger",
        onClick: function onClick() {
          return _this2.triggerError(500);
        }
      }, intl.get('cpaas.exceptionComponent.view.button.trigger500').d('触发500')), /*#__PURE__*/React.createElement(Button, {
        type: "danger",
        onClick: function onClick() {
          return _this2.triggerError(404);
        }
      }, intl.get('cpaas.exceptionComponent.view.button.trigger404').d('触发404'))));
    }
  }]);

  return TriggerException;
}(PureComponent)) || _class) || _class);
export { TriggerException as default };